/**
 * 文 件 名:  OSSUploadManager.java
 * 版    权:  Technologies Co., Ltd. Copyright YYYY-YYYY,  All rights reserved
 * 描    述:  <描述>
 * 修 改 人:  baoyinbo 00501
 * 修改时间:  16/6/29
 * 跟踪单号:  <跟踪单号>
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */

package com.shuaiche.yeguan.net.oss;


import com.alibaba.sdk.android.oss.OSS;
import com.alibaba.sdk.android.oss.model.PutObjectRequest;
import com.shuaiche.yeguan.SCApplication;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;

/**
 * oos上传管理
 *
 */
public class OSSUploadManager {

    /**
     * oss客户端
     */
    private OSS ossClient;

    public OSSUploadManager(String accessKeyId, String accessKeySecret, String securityToken) {
        ossClient= SCApplication.getApplication().getOssClient(accessKeyId, accessKeySecret, securityToken);
    }

    /**
     * 单例模式获取OSS管理者
     *
     * @return
     */
//    public static OSSUploadManager getInstance() {
//        return uploadManager;
//    }

    /***
     * 上传多个文件
     * @param bodys
     * @param callback
     */
    public void asyncUploadList(@NonNull List<OSSRequestBody> bodys, OSSUploadCallback callback){
        OSSUploadTask task=new OSSUploadTask(ossClient);
        List<PutObjectRequest> requests=new ArrayList<PutObjectRequest>();
        for(OSSRequestBody body:bodys){
            requests.add(body.getRequest());
        }
        task.addAll(requests);
        task.upload(callback);
    }

    /***
     * 上传多个文件
     * @param bodys
     * @param callback
     */
    public void asyncUploadBitmapList(@NonNull List<OSSRequestBody> bodys,OSSUploadCallback callback){
        OSSUploadBitmapTask task=new OSSUploadBitmapTask(ossClient);
        task.addAll(bodys);
        task.upload(callback);
    }

    /***
     *
     * 上传单个文件
     * @param body
     * @param callback
     */
    public void asyncUpload(@NonNull OSSRequestBody body,OSSUploadCallback callback){
        OSSUploadTask task=new OSSUploadTask(ossClient);
        task.add(body.getRequest());
        task.upload(callback);
    }

    public void asyncUploadByUri(@NonNull OSSRequestBody body,OSSUploadCallback callback){
        OSSUploadTask task=new OSSUploadTask(ossClient);
        task.add(body.getRequestByUri());
        task.upload(callback);
    }

    public void asyncUploadBitmap(@NonNull OSSRequestBody body,OSSUploadCallback callback){
        OSSUploadBitmapTask task=new OSSUploadBitmapTask(ossClient);
        task.add(body);
        task.upload(callback);
    }
}
